﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using SystemCenterSoa.ApiLibrary.PermissionsValidation;
using SystemCenterSoa.DtoModel.Common;
using SystemCenterSoa.DtoModel.SystemManager;
using SystemCenterSoa.PoModel.SystemManager;
using SystemCenterSoa.Service.SystemManager;

namespace SystemCenterSoa.ApiProject.Area.SystemManager
{
    [ApiModuleRelation("dibage")]
    public class RoleManagerController : SystemManagerBaseController
    {
        private RoleService _RoleService;
        public RoleManagerController(RoleService RoleService)
        {
            _RoleService = RoleService;
        }
        [HttpGet]
        public ResultModel<RoleDto> GetRoleDtoById(int roleId)
        {
            try
            {
                var data = _RoleService.GetRoleDtoById(roleId);
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<RoleDto>(ex);
            }
        }
        [HttpPost]
        public ResultModel<PagerResult<RolePo>> SearchPage(SearchModel sm)
        {
            try
            {
                var data = _RoleService.SearchPage(sm);
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<PagerResult<RolePo>>(ex, null);
            }


        }
        /// <summary>
        /// 角色添加
        /// </summary>
        /// <param name="view"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultModel<int> RolePoAdd(RoleDto view)
        {
            try
            {
                var data = _RoleService.RolePoAdd(view);
                if (data == 0)
                {
                    return MyFail<int>("添加没有成功！");
                }
                return MyOk(data);
            }
            catch (Exception ex)
            {

                return MyError<int>(ex);
            }
        }

        [HttpPost]
        public ResultModel<bool> RolePoUpdate(RoleDto view)
        {
            try
            {
                var data = _RoleService.RoleUpdate(view);
                if (data)
                {
                    return MyOk(data);
                }
                return MyFail<bool>("更新没有成功！");
            }
            catch (Exception ex)
            {
                return MyError<bool>(ex);
            }
        }

        //public PagerResult<RolePo>SearchPage(SearchModel searchModel)
        //{

        //}

    }
}
